<template>
  <div class="discipline">
    <el-card>
      <el-row :gutter="20">
        <el-col :span="18">
          <el-form :inline="true" :model="formInline.query" class="demo-form-inline">
            <el-form-item label="目录名称">
              <el-input v-model="formInline.user"></el-input>
            </el-form-item>
            <el-form-item label="状态">
              <el-select v-model="formInline.region" placeholder="请选择">
                <el-option label="区域一" value="shanghai"></el-option>
                <el-option label="区域二" value="beijing"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button size="medium">清除</el-button>
              <el-button type="primary" @click="onSubmit" size="medium "
                >搜索</el-button
              >
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="6" style="text-align: right">
          <div>
            <el-button
              type="success"
              size="medium"
              class="xinzheng"
              icon="el-icon-edit"
              >新增目录</el-button
            >
          </div>
        </el-col>
      </el-row>
      <el-alert
        class="warn"
        title="一共有8条数据"
        type="info"
        show-icon
        :closable="false"
      >
      </el-alert>
      <!-- 用户列表区域 -->
      <el-table :data="channels">
        <el-table-column label="序号" type="index"></el-table-column>
        <el-table-column label="所属学科" prop="subjectName"></el-table-column>
        <el-table-column
          label="目录名称"
          prop="directoryName"
        ></el-table-column>
        <el-table-column label="创建者" prop="username"></el-table-column>
        <el-table-column label="创建日期" prop="addDate"></el-table-column>
        <el-table-column label="面试题数量" prop="totals"></el-table-column>
        <el-table-column label="状态" prop="state">
          <span v-if="channels.state">已开启</span>
          <span v-else>已关闭</span>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="">
            <span>禁用</span>
            <span>修改</span>
            <span>删除</span>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryinfo.pagesize"
        :page-sizes="[1, 2, 5, 10]"
        :page-size="queryinfo.page"
        layout="sizes, prev, pager, next, jumper"
        background
        :total="total"
      >
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
import { directorylist } from "../../api/subject";

export default {
  name: "directorylist",
  components: {},
  props: {},
  data() {
    return {
      queryinfo: {
        query: "",
        page: 1, //当前页数
        pagesize: 1, //每页显示多少条数据
      },
      total: 0,
      channels: [],
      formInline: {
        user: "",
        region: "",
      },
    };
  },
  computed: {},
  watch: {},
  created() {
    this.loadChannels();
  },
  mounted() {},
  methods: {
    // 当每页多少条数据发生变化时触发的函数
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    // 页数发生变化时触发的函数
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    },
    async loadChannels() {
      try {
        const { data } = await directorylist();
        // console.log(data, 111);
        this.channels = data.items;
        console.log(this.channels);
        this.total = data.counts;
      } catch (err) {
        console.log(err);
      }
    },

    onSubmit() {},
  },
};
</script>

<style scoped lang="less">
/deep/td {
  .cell {
    span {
      padding: 3px;
      color: #409eff;
    }
  }
}
.el-select {
  margin-left: 15px;
}
.el-pagination {
  margin-top: 10px;
}
</style>
